package com.sykj.manage.web;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sykj.manage.service.SysUserService;
import com.sykj.manage.model.SysUser;
import com.sykj.util.MD5Util;
/**
 * 
 * @author 高志远
 *2018年9月13日下午3:48:36
 *类描述:用户表[sys_user控制类
 */
import com.sykj.util.ManageBody;
import com.sykj.util.PageUtil;
@Controller
@RequestMapping("/sys")
public class SysUserConller {
	
	@Autowired
	SysUserService sysUserService;
	
	/**
	 * 用户管理查询
	 * @param sysUser
	 * @return
	 */
	@RequestMapping("/findUser")
	@ResponseBody
	public ManageBody finduser(SysUser sysUser,Integer offset,Integer pageSize){
		PageHelper.startPage(offset==null?1:PageUtil.getPageNum(offset, pageSize),pageSize==null?10:pageSize,true);
		List<SysUser> users = sysUserService.FindUsers(sysUser);
		PageInfo<SysUser> pageInfo = new PageInfo<SysUser>(users);
		return ManageBody.getData((int)pageInfo.getTotal(), pageInfo.getList(), "");
		
	}
	
	@RequestMapping("/addUser")
	@ResponseBody
	public Object adduser(SysUser sysUser){
		Date date = new Date();
		sysUser.setCreate_time(date);
		//给密码加密
		String password = MD5Util.jiami(sysUser.getAccount(), sysUser.getPassword());
		sysUser.setPassword(password);
		int addUser = sysUserService.addUser(sysUser);
		return addUser;
		
	}
	
	/**
	 * 删除用户
	 * @param user_id
	 * @return
	 */
	@RequestMapping("/delUsers")
	@ResponseBody
	public Object delMenus(@RequestParam("user_id")String[] user_id) {
		int cnt = sysUserService.delUsers(user_id);
		return cnt;
	}
	
	
	@RequestMapping("/findUserById")
	@ResponseBody
	public Object findUserById(String user_id) {
		SysUser findUserById = sysUserService.findUserById(user_id);
		return findUserById;
	}
	
	/**
	 * @param sysUser
	 * @return
	 * 修改
	 */
	@RequestMapping("/updUser")
	@ResponseBody
	public Object updUser(SysUser sysUser){
		Date date = new Date();
		sysUser.setCreate_time(date);
		int updUser = sysUserService.updUser(sysUser);
		return updUser;
		
	}

}
